﻿Imports BusinessRule.IBusiness
Imports BusinessRule.DTO
Imports BusinessRule.BusinessFactory

Partial Class forms_shopfloor_uMESDocPrint_ZSContainerNoInfoPrintForm
    Inherits System.Web.UI.Page
    Private m_issueData As uLMSIssueERPMaterialIbusiness = uMESBusinessFactory.instance.GetuLMSIssueERPMaterialObject
    Public htmlstr As String
    Public strHtmlTable As String
    Private Shared i_PageRowCount As Integer = 25 '设置每页打印24行
    Private Shared i_BottomRowCount As Integer = 10

#Region "事件"
    Protected Sub OnPageLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
            If Session("ContainerPrint") Is Nothing Then
                Exit Sub
            End If
            Dim dt As DataTable = Session("ContainerPrint")
            For Each dr As DataRow In dt.Rows
                iniPate(dr)
            Next
        End If
    End Sub

#End Region
#Region "方法"
    Protected Sub iniPate(ByVal dr As DataRow)
        Dim strHtmlTitle As String
        Dim strHtmlTableMain As String
        Dim strHtmlTableDetails As String
        strHtmlTitle = SetTableTitle(dr)
        strHtmlTableMain = SetTableMain(dr)
        strHtmlTableDetails = SetTableDetail(dr)
        strHtmlTable = String.Format("{0}{1}{2}{3}", strHtmlTable, strHtmlTitle, strHtmlTableMain, strHtmlTableDetails)
    End Sub

    Private Function SetTableTitle(ByVal dr As DataRow) As String
        Return String.Empty
    End Function

    Private Function SetTableMain(ByVal dr As DataRow) As String
        Return String.Empty
    End Function

    Private Function SetTableDetail(ByVal dr As DataRow) As String
        Dim para As New Dictionary(Of String, String)
        para("WorkflowId") = dr("WorkflowId")
        para("ContainerId") = dr("ContainerId")
        para("PhaseNode") = dr("phasenode")
        Dim dt As DataTable = m_issueData.GetStepCheckPointData(para)
        GetsbHtml(dt, dr)
        Return htmlstr
    End Function

    Private Function AddHeaderBlank() As String
        Dim sb As New StringBuilder
        sb.AppendLine("<table>")
        sb.AppendLine("<tr><td width='650' height='70'></td></tr></table>")
        Return sb.ToString
    End Function

    Private Function SetHeader(ByVal dr As DataRow) As String
        Dim sb As New StringBuilder
        sb.AppendLine(" <table class='tbMain'>")
        sb.AppendLine("<tr><td colspan='2' width='150'>中国航发贵州黎阳航空动力有限公司</td>")
        sb.AppendFormat("<td rowspan='2' style='font-size:30px' width='300'><strong>{0}</strong></td>", dr("ProductDesc"))
        sb.AppendFormat("<td width='80'>发动机号</td><td >{0}</td></tr>", dr("EngineName"))

        sb.AppendFormat("<tr><td width='18'>型别</td><td >{0}</td>", dr("productfamilyname"))
        sb.AppendFormat("<td>组合件号</td><td>{0}</td></tr>", dr("productname"))
        sb.AppendLine("</table>")
        Return sb.ToString
    End Function

    Private Function SetMainTitle() As String
        Dim sb As New StringBuilder
        sb.AppendLine(" <table class=tbDetail>")
        sb.AppendLine("<tr>")
        sb.AppendLine("<td width='26'>序号</td>")
        sb.AppendLine("<td>检验项目</td>")
        sb.AppendLine("<td>图纸规定</td>")
        sb.AppendLine("<td>实际</td>")
        sb.AppendLine("<td>工人</td>")
        sb.AppendLine("<td>检验员</td>")
        sb.AppendLine("</tr>")
        sb.AppendLine("</table>")
        Return sb.ToString
    End Function

    Private Function SetMainBottom(ByVal i_height As Integer) As String
        Dim sb As New StringBuilder
        sb.AppendLine("<table class=tbBottom > ")
        sb.AppendLine("<tr> ")
        sb.AppendLine("<td colspan='6' style='border: 1px solid blue;text-align:left'>结论：本工序已按现行工艺规程，技术通知等有关技术要求装配并验收合格</td> ")
        sb.AppendLine("<td width='123' style='border: 1px solid blue;'>&nbsp;</td> ")
        sb.AppendLine("</tr>  <tr> ")
        sb.AppendLine("<td width='46'>附注：</td> ")
        sb.AppendLine("<td colspan='6'>&nbsp;</td> ")
        sb.AppendLine("</tr>  <tr> ")
        sb.AppendFormat("<td height={0} colspan='7'>&nbsp;</td> ", i_height * 30)
        sb.AppendLine("</tr>  <tr> ")
        sb.AppendLine("<td>&nbsp;</td>")
        sb.AppendLine("<td width='115'>生产工（组）长：</td>")
        sb.AppendLine("<td width='158'>&nbsp;</td>")
        sb.AppendLine("<td width='71'>检验工长：</td>")
        sb.AppendLine("<td colspan='3'>&nbsp;</td>")
        sb.AppendLine("</tr>  <tr>")
        sb.AppendLine(" <td colspan='4'>&nbsp;</td>")
        sb.AppendLine("<td width='41'>年</td>")
        sb.AppendLine("<td width='41'>月</td>")
        sb.AppendLine("<td>日</td>")
        sb.AppendLine("</tr>  </table> ")
        Return sb.ToString
    End Function

    Private Sub GetsbHtml(ByVal dt As DataTable, ByVal dr As DataRow)
        '没有检测项时
        Dim htmlHeader As String = String.Empty, htmlTitle As String = String.Empty, htmlBottom As String = String.Empty
        Dim sb As New StringBuilder
        If dt.Rows.Count = 0 Then
            htmlHeader = SetHeader(dr)
            htmlTitle = SetMainTitle()
            htmlBottom = SetMainBottom(20)
            sb.AppendLine(String.Format("{0}{1}{2}", htmlHeader, htmlTitle, htmlBottom))
        Else
            '思路：
            '表头占有行数，检验项占有行数，如果一行文字数超过20换行
            '如果需要分页，最后一页需要打印结论表格，表格占据10行
            Dim CurrentPage As Integer = 0
            Dim dtCount As Integer = dt.Rows.Count
            Dim pageCount As Integer = Math.Ceiling((dtCount + i_BottomRowCount) / i_PageRowCount)
            For i As Integer = 0 To dtCount - 1
                If ((i Mod i_PageRowCount) = 0) Then
                    CurrentPage += 1
                    If i > 0 Then
                        Dim strBlank As String = AddHeaderBlank()
                        sb.AppendLine(strBlank)
                    End If
                    htmlHeader = SetHeader(dr)
                    sb.AppendLine(htmlHeader)
                    sb.AppendLine(" <table class=tbDetail>")
                    sb.AppendLine("<tr>")
                    sb.AppendLine("<td width='26'>序号</td>")
                    sb.AppendLine("<td>检验项目</td>")
                    sb.AppendLine("<td>图纸规定</td>")
                    sb.AppendLine("<td>实际</td>")
                    sb.AppendLine("<td>工人</td>")
                    sb.AppendLine("<td>检验员</td>")
                    sb.AppendLine("</tr>")
                End If
                sb.AppendLine("<tr>")
                sb.AppendFormat("<td>{0}</td>", (i + 1).ToString)
                sb.AppendFormat("<td>{0}</td>", dt.Rows(i)("Name"))
                sb.AppendFormat("<td>{0}</td>", dt.Rows(i)("checkpointnote"))
                sb.AppendFormat("<td>{0}</td>", dt.Rows(i)("checkpointresultnote"))
                sb.AppendFormat("<td>{0}</td>", dt.Rows(i)("worker"))
                sb.AppendFormat("<td>{0}</td>", dt.Rows(i)("checker"))
                sb.AppendLine("</tr>")
                If ((i + 1) Mod i_PageRowCount) = 0 Then
                    sb.AppendLine("</table>")
                End If

                If ((i + 1) Mod i_PageRowCount <> 0) And (i = dtCount - 1) Then
                    sb.AppendLine("</table>")

                    sb.AppendLine(SetMainBottom(i_PageRowCount - (dtCount Mod i_PageRowCount)))
                End If
            Next

        End If
        htmlstr = sb.ToString
    End Sub
#End Region


End Class
